﻿<%@ Page Language="C#" MasterPageFile="~/Common/Master/PopTree.master" AutoEventWireup="true"
    Inherits="Common_TreeDlg" Title="无标题页" CodeBehind="TreeDlg.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    
    <script type="text/javascript">
    
        <!--
        var setting =
        {
            view:
            {
                showIcon: false
            },
            check: {
                enable: true,
                chkboxType: { "Y": "", "N": "" }
                //                chkStyle :"radio",
                //                radioType : "all"
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {

                beforeCheck: function (treeid, treeNode)
                {
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                    if ('<%=Request["SingleSelect"] %>' == 'true')
                    {
                        var nodes = zTree.getCheckedNodes();
                        for (var i = 0; i < nodes.length; i++)
                        {
                            zTree.checkNode(nodes[i], false, false, false);
                        }
                    }
                },
                onCheck: function (event, treeid, treeNode)
                {
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                    if ('<%=Request["SingleSelect"] %>' != 'true' && treeNode.children != null)
                    {
                        for (var i = 0; i < treeNode.children.length; i++)
                        {
                            zTree.setChkDisabled(treeNode.children[i], treeNode.checked);
                        }

                    }
                },
                onClick: function (event, treeid, treeNode)
                {
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                    //zTree.expandNode(treeNode);
                    zTree.checkNode(treeNode, !treeNode.checked, false, true);//单击节点可以选中（取消）checkbox

                    zTree.cancelSelectedNode(treeNode);//取消选中状态

                }
            }

        };

        eval("var zNodes = [ <asp:Literal ID='lblJson' runat='server'  EnableViewState='false'></asp:Literal>  ];");


//        var zNodes = [
//			{ id: 1, pId: 0, name: "随意勾选 1", open: true },
//			{ id: 11, pId: 1, name: "随意勾选 1-1", open: true },
//			{ id: 111, pId: 11, name: "disabled 1-1-1", chkDisabled: true },
//			{ id: 112, pId: 11, name: "随意勾选 1-1-2" },
//			{ id: 12, pId: 1, name: "disabled 1-2", chkDisabled: true, checked: true, open: true },
//			{ id: 121, pId: 12, name: "disabled 1-2-1", checked: true },
//			{ id: 122, pId: 12, name: "disabled 1-2-2" },
//			{ id: 2, pId: 0, name: "随意勾选 2", checked: true, open: true },
//			{ id: 21, pId: 2, name: "随意勾选 2-1" },
//			{ id: 22, pId: 2, name: "随意勾选 2-2", open: true },
//			{ id: 221, pId: 22, name: "随意勾选 2-2-1", checked: true },
//			{ id: 222, pId: 22, name: "随意勾选 2-2-2" },
//			{ id: 23, pId: 2, name: "随意勾选 2-3" }
//		];


        $(document).ready(function ()
        {
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);

            initSelect('<%=RestoreIDs %>');

        });


        function btn_click()
        {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            var nodes = zTree.getCheckedNodes();
          
            var ids = "";
            var names = "";
            for (var i = 0; i < nodes.length; i++)
            {
                if (nodes[i].chkDisabled != true)
                {
                    ids += "," + nodes[i].id;
                    names += "," + nodes[i].name;
                }
            }

            var args = window.dialogArguments;

            if (ids != "")
            {
                args[0] = ids.substr(1);
                args[1] = names.substr(1);
            }

            
            window.close();
        }

       

        function initSelect(strIDs)
        {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");

            var ids = strIDs.split(',');
            for (var i = 0; i < ids.length; i++)
            {
                if (ids[i] != "")
                {
                    var node = zTree.getNodesByParam("id", ids[i], null)[0];
                    zTree.checkNode(node, true, false, true);

                    var parentNode = node.getParentNode();
                    if (parentNode != null)
                    {
                        zTree.expandNode(parentNode, true, false, false, false);
                    }

                }
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Label ID="lblTitle" runat="server" Text="选择模块"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <ul id="treeDemo" class="ztree">
    </ul>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server">
    <input id="Button1" type="button" value="确定" onclick="btn_click()" />
</asp:Content>
